package com.jf.hotelreservation.demos.service.impl;

import com.alibaba.fastjson2.JSON;
import com.jf.hotelreservation.demos.bean.Room;
import com.jf.hotelreservation.demos.mapper.RoomMapper;
import com.jf.hotelreservation.demos.service.RoomService;
import com.jf.hotelreservation.demos.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;
    @Override
    public String queryAll(Integer hid) {
        List<Room> roomList = roomMapper.queryAll(hid);
        return JSON.toJSONString(R.success(roomList));
    }

    @Override
    public String addRoom(Room room) {
        if (roomMapper.addRoom(room) != 0){
            return JSON.toJSONString(R.success("操作成功"));
        }else {
            return JSON.toJSONString(R.error("操作失败"));
        }

    }

    @Override
    public String queryRoom(Integer id) {
        return JSON.toJSONString(R.success(roomMapper.queryById(id)));
    }
}
